package com.xiaoy.util.collection;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class OrderMap<k,v>{

	private List<KeyValue<k,v>> index = new ArrayList<KeyValue<k,v>>();

	public boolean isEmpty() {
		
		return index.size()==0;
	}

	public void put(k key, v value) {
		
		index.add(new KeyValue(key,value));
	}

	public void putAll(Map<? extends k, ? extends v> m) {
		
		for (java.util.Map.Entry<? extends k, ? extends v> entry: m.entrySet()) {
			index.add(new KeyValue(entry.getKey(),entry.getValue()));
		}
	}
	
	public void remove (k key) {
		for (int i =0;i<index.size();i++) {
			KeyValue kv = index.get(i);
			if (kv.getKey() == key) {
				index.remove(i);
				return ;
			}
		}
	}
	
	public void clear () {
		index.clear();
	}
	
	public v get (k key) {
		
		for (int i =0;i<index.size();i++) {
			KeyValue<k,v> kv = index.get(i);
			if (kv.getKey() == key) {
				return kv.getValue();
			}
		}
		return null;
	}
	
	private class KeyValue<k,v> {
		
		private k key;
		private v value;
		
		public KeyValue (k key,v value){
			this.key=key;
			this.value=value;
		}
		public KeyValue (){
		}
		public k getKey() {
			return key;
		}
		public void setKey(k key) {
			this.key = key;
		}
		public v getValue() {
			return value;
		}
		public void setValue(v value) {
			this.value = value;
		}
	}
}
